#include "API.h"
#include <stdlib.h>
#include <iostream>
#include <string.h>
#include <sys/msg.h>

extern "C" Quiface* create_t()
{
  return new Quiface;
}

extern "C" void destroy_t( Quiface* object )
{
  delete object;
}

bool Quiface::quality_of_control=false;

inline Quiface::Quiface(long P,int ssize, int tnumber ){
    
    api_queue_id=Message_queue_setup(API_QUEUE_KEY);
    if(api_queue_id==EXIT_SUCCESS){
        
        PORT=P;
        stuct_size=ssize;
        int t_number=tnumber;
        quality_of_control=true;
        p_this=this;
        
    }
    else
    {
        quality_of_control=false;
        std::cout<<"El API ha fallado en crear la cola de mensaje,"
                "verifique que cuenta con los privilegios de Root\n";
        
    }

}

inline Quiface::Quiface(){}
inline Quiface::~Quiface(){}

inline void *Quiface::Qfilter(void*t){
    
    while(true){
    Quiface *f=(Quiface*)t; 
    bzero((char *) &f->raw_data, sizeof(f->raw_data));
    msgrcv(f->api_queue_id,(struct msgbuf *)&f->raw_data,sizeof(f->raw_data)-sizeof(long),f->PORT,0);
    
    Message_queue *buff = (Message_queue*)&f->raw_data;
    switch(buff->package.header.type_message){
       
        case MISSING_CONFIRMATION:{
            std::cout<<"he recibido:"<<int(buff->package.header.type_message); 
            break;
        }
    }
   }
}


int main(){
}
